package com.imooc.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/** 有效期类型枚举类
 * @description:
 * @author：naxiaozi，微信：naxiaozi
 * @date: 2025/8/12
 * @Copyright：
 */
@Getter
@AllArgsConstructor
public enum PeriodType {
    REGULAR("固定日期的类型",1),
    SHIFT("变动(以领取之日开始计算)",2);
    private String description;
    private Integer code;
    public static PeriodType of(Integer code){
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean->bean.code.equals(code))
                .findAny()
                .orElseThrow(()->new IllegalArgumentException(code+" not exist"));
    }
}
